/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 123
 * Date: 2023-05-24
 * Time: 9:01
 */
class  MyList{

  public ListNode head ;
    public void addNode(int i){
        ListNode node = new ListNode(i);
        node.next = null ;
        if(this.head == null){
            this.head = node ;
            return;
        }
        ListNode cur = this.head ;
        while(cur .next != null ){
            cur =cur.next ;
        }
        cur.next = node ;
        node.next = null ;
    }
 public void diPlay(){
        ListNode cur = head ;
        while(cur != null){
            System.out.print(cur.val + "  ");
            cur = cur.next ;
        }
     System.out.println();

 }

    class ListNode {
       public int val;
      public     ListNode next = null;

        ListNode(int val) {
            this.val = val;
        }

    }
    public  int size() {
        int count = 0;
        ListNode cur = this.head;
        while (cur != null) {
            cur = cur.next;
            count ++ ;
        }
        return count;

    }
    public int FindKthToTail( int k) {
        if (k < 1 || k > size()) {
            return 0;
        }
        ListNode fast = head;
        ListNode slow = head;
        while (k - 1 != 0) {
            fast = fast.next;
            k--;
        }
        while (fast.next != null) {
            slow = slow.next;
            fast = fast.next;
        }

        return slow.val;


    }


}
